package com.file.controller;

import com.file.pojo.User;
import com.file.service.UserService;
import com.file.vo.PageResult;
import com.file.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user")
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;

    //用户展示
    @RequestMapping("/login")
    private SysResult login(@RequestBody User user){
        //执行后端登录操作,要求返回token密钥
        String token = userService.login(user);
        //判断token返回值是否有效
        if(StringUtils.hasLength(token)){
            return SysResult.success(token);
        }else{
            //登录失败
            return SysResult.fail();
        }
    }

    //分页展示
    @GetMapping("/list")
    public SysResult getUserList(PageResult pageResult){
        pageResult = userService.getuserlist(pageResult);
        return SysResult.success(pageResult);
    }


}
